<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for src/utils/httpRequest.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="..\..\prettify.css" />
    <link rel="stylesheet" href="..\..\base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(..\..\sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="..\..\index.html">All files</a> / <a href="index.html">src/utils</a> httpRequest.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/43</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/38</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/8</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/27</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import Vue fr<span class="cstat-no" title="statement not covered" >om 'vue'<span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ></span></span></span></span></span></span></span>
import axios <span class="cstat-no" title="statement not covered" >from 'axios'<span class="cstat-no" title="statement not covered" ></span></span>
import router <span class="cstat-no" title="statement not covered" >from '@/router'<span class="cstat-no" title="statement not covered" ></span></span>
import qs <span class="cstat-no" title="statement not covered" >from 'qs'<span class="cstat-no" title="statement not covered" ></span></span>
import merge <span class="cstat-no" title="statement not covered" >from 'lodash/merge'<span class="cstat-no" title="statement not covered" ></span></span>
import { clea<span class="cstat-no" title="statement not covered" >rLoginInfo } from '</span>@/utils'<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" ></span></span>
&nbsp;
const http <span class="cstat-no" title="statement not covered" >= axios.create({</span>
  timeout: 1000 * 30,
  withCredentials: true,
  headers: {
    'Content-Type': 'application/json; charset=utf-8'
  }
})
&nbsp;
/**
 * 请求拦截
 */
<span class="cstat-no" title="statement not covered" >http.interceptors.request.use(<span class="fstat-no" title="function not covered" >co</span>nfig =&gt; {</span>
<span class="cstat-no" title="statement not covered" >  config.headers['token'] = Vue.cookie.get('token') // 请求头带上tok</span>en
<span class="cstat-no" title="statement not covered" >  return config</span>
}, <span class="fstat-no" title="function not covered" >er</span>ror =&gt; {
<span class="cstat-no" title="statement not covered" >  return Promise.reject(error)</span>
})
&nbsp;
/**
 * 响应拦截
 */
<span class="cstat-no" title="statement not covered" >http.interceptors.response.use(<span class="fstat-no" title="function not covered" >re</span>sponse =&gt; {</span>
<span class="cstat-no" title="statement not covered" >  if (response.data &amp;&amp; response.data.code === 401) { // 401, token失效</span>
<span class="cstat-no" title="statement not covered" >    clearLoginInfo()</span>
<span class="cstat-no" title="statement not covered" >    router.push({ name: 'login' })</span>
  }
<span class="cstat-no" title="statement not covered" >  return response</span>
}, <span class="fstat-no" title="function not covered" >er</span>ror =&gt; {
<span class="cstat-no" title="statement not covered" >  return Promise.reject(error)</span>
})
&nbsp;
/**
 * 请求地址处理
 * @param {*} actionName action方法名称
 */
<span class="cstat-no" title="statement not covered" >http.adornUrl = <span class="fstat-no" title="function not covered" >(a</span>ctionName) =&gt; {</span>
  // 非生产环境 &amp;&amp; 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
<span class="cstat-no" title="statement not covered" >  return (process.env.NODE_ENV !== 'production' &amp;&amp; process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName</span>
}
&nbsp;
/**
 * get请求参数处理
 * @param {*} params 参数对象
 * @param {*} openDefultParams 是否开启默认参数?
 */
<span class="cstat-no" title="statement not covered" >http.adornParams = <span class="fstat-no" title="function not covered" >(p</span>arams = {}, openDefultPa<span class="cstat-no" title="statement not covered" >rams = true) =&gt; {<span class="cstat-no" title="statement not covered" ></span></span></span>
  var defaults = <span class="cstat-no" title="statement not covered" >{</span>
    't': new Date().getTime()
  }
<span class="cstat-no" title="statement not covered" >  return openDefultParams ? merge(defaults, params) : params</span>
}
&nbsp;
/**
 * post请求数据处理
 * @param {*} data 数据对象
 * @param {*} openDefultdata 是否开启默认数据?
 * @param {*} contentType 数据格式
 *  json: 'application/json; charset=utf-8'
 *  form: 'application/x-www-form-urlencoded; charset=utf-8'
 */
<span class="cstat-no" title="statement not covered" >http.adornData = <span class="fstat-no" title="function not covered" >(d</span>ata = {}, openDefultda<span class="cstat-no" title="statement not covered" >ta = true, contentType = 'json') =&gt; {<span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ></span></span></span></span>
  var defaults = <span class="cstat-no" title="statement not covered" >{</span>
    't': new Date().getTime()
  }
<span class="cstat-no" title="statement not covered" >  data = openDefultdata ? merge(defaults, data) : data</span>
<span class="cstat-no" title="statement not covered" >  return contentType === 'json' ? JSON.stringify(data) : qs.stringify(data)</span>
}<span class="cstat-no" title="statement not covered" ></span>
&nbsp;
export default http
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Sep 20 2018 10:14:21 GMT+0800 (中国标准时间)
</div>
</div>
<script src="..\..\prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="..\..\sorter.js"></script>
</body>
</html>
